package good

import (
	"api/pb/good"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodLogic {
	return &CreateGoodLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGoodLogic) CreateGood(req *types.Good) (*types.Empty, error) {
	_, err := l.svcCtx.GoodRpc.CreateGood(l.ctx, &good.GoodInfo{
		Name:  req.Name,
		Price: req.Price,
		Stock: req.Stock,
	})
	return &types.Empty{}, err
}
